<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Sets the fields for a query</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="mongocursor.explain.html">« MongoCursor::explain</a></li>
      <li style="float: right;"><a href="mongocursor.getnext.html">MongoCursor::getNext »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="class.mongocursor.html">MongoCursor</a></li>
    <li>Sets the fields for a query</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="mongocursor.fields" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">MongoCursor::fields</h1>
  <p class="verinfo">(PECL mongo &gt;=1.0.6)</p><p class="refpurpose"><span class="refname">MongoCursor::fields</span> &mdash; <span class="dc-title">Sets the fields for a query</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-mongocursor.fields-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>MongoCursor::fields</strong></span>(<span class="methodparam"><span class="type">array</span> <code class="parameter">$f</code></span>): <span class="type"><a href="class.mongocursor.html" class="type MongoCursor">MongoCursor</a></span></div>

  <p class="para rdfs-comment">
   Fields are specified by <code class="literal">&quot;fieldname&quot; : bool</code>.  <strong><code>true</code></strong> 
   indicates that a field should be returned, <strong><code>false</code></strong> indicates that it should
   not be returned.  You can also use 1 and 0 instead of <strong><code>true</code></strong> and <strong><code>false</code></strong>.
  </p>
  <p class="para">
   Thus, to return only the &quot;summary&quot; field, one could say:
  </p>
  <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br />$cursor</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">fields</span><span style="color: #007700">(array(</span><span style="color: #DD0000">"summary"&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">true</span><span style="color: #007700">));<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
  </div>

  <p class="para">
   To return all fields except the &quot;hidden&quot; field:
  </p>
  <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br />$cursor</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">fields</span><span style="color: #007700">(array(</span><span style="color: #DD0000">"hidden"&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">false</span><span style="color: #007700">));<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
  </div>

 </div>


 <div class="refsect1 parameters" id="refsect1-mongocursor.fields-parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">
   <dl>

    
     <dt>

      <code class="parameter">f</code>
     </dt>

     <dd>

      <p class="para">
       Fields to return (or not return).
      </p>
     </dd>

       
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-mongocursor.fields-returnvalues">
  <h3 class="title">Return Values</h3>  
  <p class="para">
   Returns this cursor.
  </p>
 </div>


 <div class="refsect1 errors" id="refsect1-mongocursor.fields-errors">
  <h3 class="title">Errors/Exceptions</h3>
  <p class="para">
   Throws <a href="class.mongocursorexception.html" class="classname">MongoCursorException</a> if this cursor has started
   iterating or a scalar argument is given.
  </p>
 </div>

</div></div></div></body></html>